﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace dst
{
    class Term
    {
        Exp coeff;
        int deg;
        const string var = "x";

        private Term()
        {
        }

        public Term(string s, int d, int i)
        {
            coeff = Ele.GetEle(s, i);
            deg = d;
        }

        public Term(Exp sop, int d)
        {
            this.coeff = sop;
            this.deg = d;
        }

        public int Degree
        {
            get { return deg; }
            set { deg = value; }
        }

        public Exp Coeff
        {
            get { return coeff; }
        }

        public bool IsEmpty()
        {
            return coeff == Exp.Zero;
        }

        public void Add(Term t)
        {
            coeff += t.coeff;
            //coeff.SortSubs();
        }

        public Term Mul(Term t)
        {
            Term r = new Term();
            r.deg = this.deg + t.deg;
            r.coeff = this.coeff * t.coeff;
            //r.coeff.SortSubs();
            return r;
        }

        public Term Clone()
        {
            Term t = new Term();
            t.coeff = this.coeff;
            t.deg = this.deg;

            return t;
        }

        public override string ToString()
        {
            return "(" + coeff.ToString() + ")*" + var + "^" + deg;
        }
    }
}
